/*
package com.ruoyi.system.util;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.system.domain.WeatherForecast;
import com.ruoyi.system.service.IWeatherForecastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class WeatherUtil {


    private static final String WEATHER_URL = "http://www.nmc.cn/rest/weather?stationid=lZXKF&_=1742117787210";
    @Autowired
    private IWeatherForecastService weatherForecastService;

    */
/**
     * 抓取天气信息
     *//*

    public static String getWeatherInfo() {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

            String result = HttpUtil.get(WEATHER_URL);
            System.out.println("result:"+result);
            JSONObject jsonObject = JSON.parseObject(result);
            JSONObject dataJsonObj = jsonObject.getJSONObject("data");
            //获取到省份和城市
            JSONObject stationObj = dataJsonObj.getJSONObject("real").getJSONObject("station");
            String province = stationObj.getString("province");
            String city = stationObj.getString("city");
            //获取未来七天的预报天气
            JSONObject predictObj = dataJsonObj.getJSONObject("predict");
            JSONArray detail = predictObj.getJSONArray("detail");
            detail.forEach(item -> {
                WeatherForecast weatherForecast = new WeatherForecast();
                JSONObject jsonObject1 = (JSONObject) item;
                JSONObject day = jsonObject1.getJSONObject("day");
                JSONObject weather = day.getJSONObject("weather");
                String info = weather.getString("info");
                Integer temperature1 = weather.getInteger("temperature");
                JSONObject wind = day.getJSONObject("wind");
                String direct = wind.getString("direct");
                String power = wind.getString("power");
                JSONObject night = jsonObject1.getJSONObject("night");
                Integer temperature2 = night.getJSONObject("weather").getInteger("temperature");
                String date = jsonObject1.getString("date");
                weatherForecast.setProvince(province);
                weatherForecast.setCity(city);
                weatherForecast.setWeatherInfo(info);
                weatherForecast.setDayWeatherTemperature(Long.valueOf(temperature1));
                weatherForecast.setNightWeatherTemperature(Long.valueOf(temperature2));
                weatherForecast.setWindDirect(direct);
                weatherForecast.setWindPower(power);
                try {
                    Date parse = simpleDateFormat.parse(date);
                    weatherForecast.setDate(parse);
                    weatherForecastService.insertWeatherForecast(weatherForecast)
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                System.out.println("日期："+jsonObject1.getString("date")+"  "+"天气："+jsonObject1.getString("weather")+"  "+"温度："+jsonObject1.getString("temperature")+"  "+"风向："+jsonObject1.getString("wind_direction")+"  "+"风力："+jsonObject1.getString("wind_power"));
            });
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }


    public static void main(String[] args) {
        getWeatherInfo();
    }
}
*/
